package main

import (
	"fmt"
	"time"

	"github.com/miscgo/sorm/model/org"
	"github.com/miscgo/sorm/model/user"
	"github.com/miscgo/sorm/singleton"
	"github.com/miscgo/sorm/util"

	"gorm.io/driver/postgres"
	"gorm.io/gorm"
)

func main() {

	begin := time.Now()
	dsn := "host=192.168.100.250 user=stcloud password=oooooo dbname=stcloud port=5432  sslmode=disable TimeZone=Asia/Shanghai"
	db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
	util.Capture(err)

	singleton.InitValidateError()
	singleton.InitGeneratesql()

	userMap := user.MigrateUser(db)
	singleton.InitUserMapping(userMap)

	orgMap := org.MigrateOrg(db)
	singleton.InitOrgMapping(orgMap)

	end := time.Now()
	fmt.Printf("total cost: %v  \n", end.Sub(begin))

	singleton.CloseGeneratesql()
	singleton.CloseValidateError()
}
